home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / CPP100.ZIP / CPPLTC2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  10.6 KB  |  243 lines

  1. /*****************************************************************************/
  2. /*       (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved         */
  3. /*****************************************************************************/
  4. /*    This source-code is NOT public domain nor Freeware, this is part of    */
  5. /*              'The C Programming Package' which is Shareware.              */
  6. /*   If you use this code, please register and get a free Full-VGA version   */
  7. /*****************************************************************************/
  8.                             /*------------------------*
  9.                              *       CPPLTC2.C        *
  10.                              *      Integrator        *
  11.                              * Manager & Applications *
  12.                              *------------------------*/
  13.  /* Included Files */
  14.  # include <stdio.h>
  15.  # include <io.h>
  16.  # include <alloc.h>
  17.  # include <time.h>
  18.  # include <conio.h>
  19.  # include <fcntl.h>
  20.  # include <sys\stat.h>
  21.  
  22.  /* Global Variables */
  23.  extern int j,bm,colour3,pfdiv;
  24.  extern unsigned int jouract,monthact,yearact;
  25.  extern long tbeginning,tend,tdiff,depdiv;
  26.  extern unsigned long nbbytes;
  27.  extern unsigned char c1,c2,nc2[],trashcan[],work[];
  28.  
  29.  /*---------*
  30.   * GET KEY *
  31.   *---------*/
  32.   int get_key()
  33.     {
  34.       /* We return a code which depends on the pressed key */
  35.       if((c1==48)||(c1==133))          return(0);          /* 0/à */
  36.       if((c1==49)||(c1==38))           return(1);          /* 1/& */
  37.       if((c1==50)||(c1==130))          return(2);          /* 2/é */
  38.       if((c1==51)||(c1==34))           return(3);          /* 3/" */
  39.       if((c1==52)||(c1==39))           return(4);          /* 4/' */
  40.       if((c1==53)||(c1==40))           return(5);          /* 5/( */
  41.       if((c1==54)||(c1==45))           return(6);          /* 6/- */
  42.       if((c1==55)||(c1==138))          return(7);          /* 7/è */
  43.       if((c1==56)||(c1==95))           return(8);          /* 8/_ */
  44.       if((c1==57)||(c1==135))          return(9);          /* 9/ç */
  45.       if((c1==65)||(c1==97))           return(10);         /* A/a */
  46.       if((c1==66)||(c1==98))           return(11);         /* B/b */
  47.       if((c1==67)||(c1==99))           return(12);         /* C/c */
  48.       if((c1==68)||(c1==100))          return(13);         /* D/d */
  49.       if((c1==69)||(c1==101))          return(14);         /* E/e */
  50.       if((c1==70)||(c1==102))          return(15);         /* F/f */
  51.       if((c1==71)||(c1==103))          return(16);         /* G/g */
  52.       if((c1==72)||(c1==104))          return(17);         /* H/h */
  53.       if((c1==73)||(c1==105))          return(18);         /* I/i */
  54.       if((c1==74)||(c1==106))          return(19);         /* J/j */
  55.       if((c1==75)||(c1==107))          return(20);         /* K/k */
  56.       if((c1==76)||(c1==108))          return(21);         /* L/l */
  57.       if((c1==77)||(c1==109))          return(22);         /* M/m */
  58.       if((c1==78)||(c1==110))          return(23);         /* N/n */
  59.       if((c1==79)||(c1==111))          return(24);         /* O/o */
  60.       if((c1==80)||(c1==112))          return(25);         /* P/p */
  61.       if((c1==81)||(c1==113))          return(26);         /* Q/q */
  62.       if((c1==82)||(c1==114))          return(27);         /* R/r */
  63.       if((c1==83)||(c1==115))          return(28);         /* S/s */
  64.       if((c1==84)||(c1==116))          return(29);         /* T/t */
  65.       if((c1==85)||(c1==117))          return(30);         /* U/u */
  66.       if((c1==86)||(c1==118))          return(31);         /* V/v */
  67.       if((c1==87)||(c1==119))          return(32);         /* W/w */
  68.       if((c1==88)||(c1==120))          return(33);         /* X/x */
  69.       if((c1==89)||(c1==121))          return(34);         /* Y/y */
  70.       if((c1==90)||(c1==122))          return(35);         /* Z/z */
  71.       if(c1==27)                       return(-1);         /* <Esc> */
  72.       if(c1==13)                       return(40);         /* <Enter> */
  73.       if(c1==32)                       return(41);         /* <Space> */
  74.       if(c1==8)                        return(42);         /* <Backspace> */
  75.       /* In all the other cases we return 99 = no choice */
  76.       return(99);
  77.     }
  78.  /*-----------------*
  79.   * GET SPECIAL KEY *
  80.   *-----------------*/
  81.   int get_special_key()
  82.     {
  83.       if(c2==59)             return(59);         /* <F1> = Help */
  84.       if(c2==60)             return(60);         /* <F2> = */
  85.       if(c2==61)             return(61);         /* <F3> = */
  86.       if(c2==62)             return(62);         /* <F4> = */
  87.       if(c2==63)             return(63);         /* <F5> = */
  88.       if(c2==64)             return(64);         /* <F6> = */
  89.       if(c2==72)             return(72);         /* <Up arrow> */
  90.       if(c2==75)             return(75);         /* <Left arrow> */
  91.       if(c2==77)             return(77);         /* <Right arrow> */
  92.       if(c2==80)             return(80);         /* <Down arrow> */
  93.       if(c2==71)             return(71);         /* <Home> */
  94.       if(c2==73)             return(73);         /* <PgUp> */
  95.       if(c2==79)             return(79);         /* <End> */
  96.       if(c2==81)             return(81);         /* <PgDn> */
  97.       if(c2==82)             return(82);         /* <Inser> */
  98.       if(c2==83)             return(83);         /* <Suppr> */
  99.       if(c2==121)            return(221);        /* Alt + 2 */
  100.       if(c2==122)            return(222);        /* Alt + 3 */
  101.       if(c2==123)            return(223);        /* Alt + 4 */
  102.       if(c2==124)            return(224);        /* Alt + 5 */
  103.       if(c2==125)            return(225);        /* Alt + 6 */
  104.       if(c2==126)            return(226);        /* Alt + 7 */
  105.       if(c2==127)            return(227);        /* Alt + 8 */
  106.       if(c2==35)             return(135);        /* Alt + H */
  107.       if(c2==46)             return(146);        /* Alt + C */
  108.       if(c2==33)             return(133);        /* Alt + F */
  109.       return(99);                 /* Other case : no choice */
  110.     }
  111.  /*----------------*
  112.   * WAIT FOR A KEY *
  113.   *----------------*/
  114.   int wait_for_a_key()
  115.     {
  116.       /* We wait for a keyboard key or a mouse button to be pressed     */
  117.       /* We foresee a high number of standard return values to use this */
  118.       /* as often as possible                                           */
  119.       while(1){
  120.     if(kbhit()){
  121.           /* we pressed a keyboard key */
  122.       c1=getch();
  123.       if(c1>0){
  124.             /* One byte key */
  125.             j=get_key();      return(j);
  126.       }
  127.       if(c1==0){
  128.  
  129.             /* 2-bytes coded key, we get the second */
  130.             c2=getch();                j=get_special_key();
  131.         return(j);
  132.       }
  133.     }
  134.         /* Else did we press a mouse button ?????? */
  135.         get_mouse_state();
  136.     if(bm==1)                      return(100);
  137.       }
  138.     }
  139.  /*------------------------*
  140.   * SET UP PRINTER MESSAGE *
  141.   *------------------------*/
  142.   int set_up_printer_message()
  143.     {
  144.       /* We save the window */
  145.  
  146. /* TO BE MODIFIED */
  147.  
  148. /*      outtextxy(437,300,"Please check the       ");
  149.         outtextxy(437,315,"printer : Switched on  ");
  150.         outtextxy(437,330,"and on line            ");
  151.         outtextxy(437,345,"<Esc> = Abord print    ");
  152.         outtextxy(437,360,"When you are ready     ");
  153.         outtextxy(437,375,"press any key or click ");
  154.       sound2();                          c1=0x20;  */
  155.       j=wait_for_a_key();
  156.       if(j==-1)                        return(0);
  157.       else                             return(1);
  158.     }
  159.  /*--------------------*
  160.   * CHECK THE VALIDITY *
  161.   *--------------------*/
  162.   int check_the_validity()
  163.     {
  164.       /* Disabled with month>12 */
  165.       get_the_system_date();
  166.       if(yearact>1994)                   return(0);
  167.       if(monthact>12)                   return(0);
  168.       return(1);
  169.     }
  170.  /*----------------------*
  171.   * GET DATE TEXT FORMAT *
  172.   *----------------------*/
  173.   void get_date_text_format()
  174.     {
  175.       /* We format the system date in xx/xx/xx */
  176.       get_the_system_date();           right_justify(jouract,2);
  177.       strcpy(trashcan,nc2);            strcat(trashcan,"/");
  178.       right_justify(monthact,2);        strcat(trashcan,nc2);
  179.       strcat(trashcan,"/");            right_justify(yearact,2);
  180.       strcat(trashcan,nc2);
  181.     }
  182.  /*--------------*
  183.   * GET DURATION *
  184.   *--------------*/
  185.   void get_duration()
  186.     {
  187.       time_t t;
  188.       t=time(NULL);                    tbeginning=t;
  189.       wait_for_a_key();
  190.       t=time(NULL);                    tend=t;
  191.       tdiff=tend-tbeginning;
  192.     }
  193.  /*---------------------*
  194.   * DISPLAY FREE MEMORY *
  195.   *---------------------*/
  196.   void display_free_memory()
  197.     {
  198.       save_screen2(54,13);        textattr(colour3);
  199.       hide_the_mouse();
  200.       gotoxy(55,15);                   cputs(" ┌─────────────────────┐ ");
  201.       gotoxy(55,16);                   cputs(" │ Available Memory  : │ ");
  202.       gotoxy(55,17);                   cputs(" │                     │ ");
  203.       gotoxy(55,18);                   cputs(" │                     │ ");
  204.       gotoxy(55,19);                   cputs(" │    Press any key    │ ");
  205.       gotoxy(55,20);                   cputs(" │       or click      │ ");
  206.       gotoxy(55,21);                   cputs(" └─────────────────────┘ ");
  207.       nbbytes=coreleft();             gotoxy(60,17);
  208.       printf("%ld bytes",nbbytes);   show_the_mouse();
  209.       wait_for_a_key();
  210.       restore_screen2(54,13);
  211.     }
  212.  /*-------------------------*
  213.   * OPEN CLEAN DIVERSE FILE *
  214.   *-------------------------*/
  215.   int open_clean_diverse_file()
  216.     {
  217.       /* We check that the file is closed before opening it */
  218.       if(pfdiv>0)                      close(pfdiv);
  219.       strcpy(trashcan,work);        strcat(trashcan,"\\DIVERS.FIC");
  220.       pfdiv=open(trashcan,O_RDWR|O_TRUNC | O_BINARY, S_IREAD|S_IWRITE);
  221.       if(pfdiv==-1){
  222.         warning(" Cannot open"," the divers file"," for an update","","");
  223.     return(0);
  224.       }
  225.       depdiv=lseek(pfdiv,0L,SEEK_SET);   return(1);
  226.     }
  227.  /*-------------------*
  228.   * OPEN DIVERSE FILE *
  229.   *-------------------*/
  230.   int open_diverse_file()
  231.     {
  232.       /* We check whether the file is closed before opening it */
  233.       if(pfdiv>0)                      close(pfdiv);
  234.       strcpy(trashcan,work);        strcat(trashcan,"\\DIVERS.FIC");
  235.       pfdiv=open(trashcan,O_RDWR | O_BINARY, S_IREAD|S_IWRITE);
  236.       if(pfdiv==-1){
  237.         warning(" Cannot open"," the divers file"," for an update","","");
  238.     return(0);
  239.       }
  240.       depdiv=lseek(pfdiv,0L,SEEK_SET);   return(1);
  241.     }
  242.  /* End of the Module */ /*-----------------------*/
  243.